package avicit.im.lantop.basic.companycorrespondence.service.api;


import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import avicit.platform6.core.jdbc.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class CompanyCorrespondenceServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/basic/companycorrespondence/rest/CompanyCorrespondenceServiceRest";

    @Autowired
    private RestClient restClient;


    /**
     *查询
     * @param page
     * @param parameter
     * @return
     */
    public Page<Map<String, Object>> loadCompanyCorrespondence(Paging<Map<String, Object>> page, Map<String, Object> parameter) {
        String url = BASE_PATH + "/getPathNameByPath";
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("parameter",parameter);
        ResponseMsg<Page<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Page<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 删除
     * @param ids
     */
    public void deleteCompanyCorrespondence(String ids) {
        String url = BASE_PATH + "/deleteCompanyCorrespondence";
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Page<Map<String, Object>>>>() {
        });

    }


    /**
     * 获取部门
     * @param orgId
     * @param orgCode
     * @param inputWord
     * @return
     */
    public Map<String, Object> getDept(String orgId, String orgCode, String inputWord) {
        String url = BASE_PATH + "/getDept";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("orgCode",orgCode);
        map.put("inputWord",inputWord);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 查询
     * @param currentDeptId
     * @param deptName
     * @return
     */
    public Boolean queryCheckData(String currentDeptId, String deptName) {
        String url = BASE_PATH + "/queryCheckData";
        Map<String,Object> map = new HashMap<>();
        map.put("currentDeptId",currentDeptId);
        map.put("deptName",deptName);
        ResponseMsg<Boolean> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Boolean>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 新增
     * @param orgId
     * @param currentDeptId
     * @param currentDeptName
     * @param deptName
     */
    public void insertCompanyCorrespondence(String orgId, String currentDeptId, String currentDeptName, String deptName) {
        String url = BASE_PATH + "/insertCompanyCorrespondence";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("currentDeptId",currentDeptId);
        map.put("currentDeptName",currentDeptName);
        map.put("deptName",deptName);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Boolean>>() {
        });
    }


    /**
     * 新增页面，选择现有部门时，需要根据已保存的对应关系，再剔除旧部门中已对应的部门
     * @param inputWord
     * @param newDeptName
     * @param orgId
     * @param orgCode
     * @return
     */
    public Map<String, Object> getOldDept(String inputWord, String newDeptName, String orgId, String orgCode) {
        String url = BASE_PATH + "/getOldDept";
        Map<String,Object> map = new HashMap<>();
        map.put("inputWord",inputWord);
        map.put("newDeptName",newDeptName);
        map.put("orgId",orgId);
        map.put("orgCode",orgCode);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
